package com.fengwk.support.util;

import java.util.Collection;
import java.util.Iterator;
import java.util.Map;

import com.fengwk.support.exception.BaseException;

/**
 * Map工具
 */
public class MapUtils {

	private MapUtils() {
		throw new BaseException("can not instance " + getClass());
	}
	
	/**
	 * Map为空判断
	 * 
	 * @param map
	 * @return
	 */
	public static boolean isBlank(Map<?, ?> map) {
		if(map == null || map.size() <= 0) {
			return true;
		}
		return false;
	}
	
	/**
	 * Map非空判断
	 * 
	 * @param map
	 * @return
	 */
	public static boolean isNotBlank(Map<?, ?> map) {
		return !isBlank(map);
	}
	
	/**
	 * 移除map中的key集合
	 * 
	 * @param map
	 * @param collection
	 */
	
	public static void removeAll(Map<?, ?> map, Collection<?> collection) {
		if(isBlank(map) || CollectionUtils.isBlank(collection)) {
			return;
		}
		Iterator<?> it = collection.iterator();
		while(it.hasNext()) {
			remove(map, it.next());
		}
	}
	
	/**
	 * 移除map中的key集合
	 * 
	 * @param map
	 * @param objs
	 */
	public static void removeAll(Map<?, ?> map, Object[] objs) {
		if(isBlank(map) || ArrayUtils.isBlank(objs)) {
			return;
		}
		for(int i = 0; i < objs.length; i++) {
			remove(map, objs[i]);
		}
	}
	
	// 移除map值
	private static Object remove(Map<?, ?> map, Object obj) {
		return map.remove(obj);
	}
	
}
